//
//  DYYuyueBottomView.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/2/4.
//  Copyright © 2021 叁拾叁. All rights reserved.
//



import UIKit
import YYText

class DYYuyueBottomView: SYBaseView {
    
    
    
    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = .white
        v.layer.shadowColor = UIColor(hex: 0xB3B3B3).cgColor
        v.layer.shadowOpacity = 0.5//阴影透明度
        v.layer.shadowOffset = CGSize(width: 0, height: -5)///阴影偏移量,四周
        v.layer.shadowRadius = 5//阴影半径  shadowPathWidth：阴影宽度
        return v
    }()
    
    let youhui: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0xAFAFAF)
        v.font = 12.autoFontSize()
        v.text = "已优惠￥0.0"
        
        return v
    }()
    
    let price: YYLabel = {
        let v:YYLabel = YYLabel()
        v.textColor = UIColor(hex: 0xF55035)
        v.font = 16.autoFontSize()
        
        return v
    }()
    
    lazy var mingxi: RYTitleImgView = {
        let v = RYTitleImgView(frame: CGRect.zero, type: .imgRight, showType: .normal, imgSuperViewMargin: 4, imgTitleMargin: 4)
        v.textLb.text = "明细"
        v.textLb.textColor = UIColor(hex: 0x666666)
        v.textLb.font = 12.autoFontSize()
        v.imageV.sy_name("jiudian_shangla")
        v.normalName = "jiudian_shangla"
        v.selectName = "meishi_xiala"
        v.tapClosure = {[weak self] (i, select) in
            if let `self` = self {
                DispatchQueue.main.async {
                    if self.currentVC.isKind(of: DYZSYuyueViewController.self) {
                        
                        let vc = self.currentVC as! DYZSYuyueViewController
                        vc.alert.isHidden = !vc.alert.isHidden
                    } else {
                        let vc = self.currentVC as! DYYuYueViewController 
                        vc.mingxi.isHidden = !vc.mingxi.isHidden
                    }
                }
            }
        }
        
        return v
    }()
    
    
    let tijiao: UIButton = {
        let v: UIButton  = UIButton(frame: CGRect(x: 0, y: 0, width: 145.autoWidth(), height: 44.autoWidth()))
        v.vg_gradLayerCreat(leftC: UIColor(hex: 0xFF7F00), rightC: UIColor(hex: 0xFF9700))
        v.setTitle("提交订单", for: .normal)
        v.setTitleColor(UIColor.white, for: .normal)
        v.titleLabel?.font = 18.autoFontSize()
        v.layer.cornerRadius = 5
        v.layer.masksToBounds = true
        return v
    }()
    
    func configure(_ priceStr: String, _ youhuiStr: String) {
        price.attributedText =  self.setPriceLb(priceStr)
        youhui.text = "已优惠￥\(youhuiStr)"
    }
    
    override func initViews() {
        price.attributedText =  self.setPriceLb("0.0")
        tijiao.addAction {[weak self] in
            if let `self` = self {
                if self.currentVC.isKind(of: DYZSYuyueViewController.self) {
                    self.clickedClosure?(0)
                } else {
                    (self.currentVC as! DYYuYueViewController).addDingdan()
                    
                }
            }
        }
        
        addSubview(bgView)
        
        addSubview(youhui)
        addSubview(price)
        addSubview(tijiao)
        addSubview(self.mingxi)
        bgView.snp.makeConstraints { (make) in
            make.top.left.right.bottom.equalToSuperview()
        }
        youhui.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(32.autoWidth())
            make.left.equalToSuperview().offset(10.autoWidth())
            make.height.equalTo(13.autoWidth())
        }
        price.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(12.autoWidth())
            make.left.equalToSuperview().offset(10.autoWidth())
            make.height.equalTo(13.autoWidth())
        }
        mingxi.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-173.autoWidth())
            make.height.equalTo(36.autoWidth())
            make.width.equalTo(50.autoWidth())
        }
        tijiao.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.height.equalTo(44.autoWidth())
            make.width.equalTo(145.autoWidth())
        }
    }
    
    
}


class DYOrderDetailView: SYBaseView {
    
    
    var bgView: UIButton = {
        let v: UIButton = UIButton()
        v.backgroundColor = UIColor.white
        return v
    }()
    
    var bgBt: UIButton = {
        let v: UIButton = UIButton()
        v.backgroundColor = UIColor(white: 0, alpha: 0.5)
        return v
    }()
    
    
    let zhifu: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1A1A1A)
        v.font = 15.autoFontSize()
        v.text  = "在线支付"
        return v
    }()
    
    let fangfei: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1A1A1A)
        v.font = 15.autoFontSize()
        
        return v
    }()
    
    let tip: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x555555)
        v.font = 13.autoFontSize()
        
        return v
    }()
    
    let gong: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 12.autoFontSize()
        
        return v
    }()
    
    let zhifuPrice: YYLabel = {
        let v = YYLabel()
        v.font = 12.autoBoldFontSize()
        
        v.textColor = UIColor(hex: 0x333333)
        return v
    }()
    
    let fangfeiPrict: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x2C2C2C)
        v.font = 12.autoFontSize()
        
        return v
    }()
    
    let zaocanPrice: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x555555)
        v.font = 12.autoFontSize()
        
        return v
    }()
    
    func configure(_ model: DYZSDetailModel, _ selectIndex: Int, _ selectTime: String, _ dayNum: Int) {
        fangfei.text  = "房费"
        
        if let c = model.roomList?[selectIndex].breakfast, c != 0 {
            tip.text  = "\(selectTime)   有早餐 \(c)人份"
        } else {
            tip.text  = "\(selectTime)   无早餐"
        }
        
        gong.text  = "\((self.currentVC as! DYZSYuyueViewController).roomNum)间\(dayNum)晚  共"
        let count = (self.currentVC as! DYZSYuyueViewController).roomNum * dayNum
        let rate = model.roomList?[selectIndex].rates ?? "0"
        let zongjia = Double(count) * (Double(rate) ?? 0.0)
        let zongjiaStr = String(format: "%.2f", zongjia)
        zhifuPrice.text = "¥\(zongjiaStr)"
        fangfeiPrict.text  = "¥\(zongjiaStr)"
        zaocanPrice.text  = "\(count)*￥\(rate)"
    }
    
    func configureMenpiao(_ title: String, _ time: String, _ type: String, _ price: String, _ num: Int) {
        fangfei.text  = title
        tip.text  = time + "  " +  type
        gong.text  = "共"
        zhifuPrice.text = "¥\(price)"
        fangfeiPrict.text  = "¥\(price)"
        zaocanPrice.text  = "\(num)*￥\(price)"
    }
    
    override func initViews() {
        self.isHidden = true
        bgBt.addAction {[weak self] in
            if let `self` = self {
                self.isHidden = true
            }
        }
        
        self.backgroundColor = .clear
        addSubview(bgBt)
        addSubview(bgView)
        
        bgView.addSubview(zhifu)
        bgView.addSubview(fangfei)
        bgView.addSubview(tip)
        
        bgView.addSubview(gong)
        bgView.addSubview(zhifuPrice)
        bgView.addSubview(fangfeiPrict)
        bgView.addSubview(lineView)
        bgView.addSubview(zaocanPrice)
        
        
        bgBt.snp.makeConstraints { (make) in
            make.height.equalTo(SCREEN_HEIGHT)
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.bottom.equalToSuperview()
        }
        bgView.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.bottom.equalToSuperview()
            make.height.equalTo(130.autoWidth())
        }
        
        zhifu.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(18.autoWidth())
            make.left.equalToSuperview().offset(17.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        fangfei.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(65.autoWidth())
            make.left.equalToSuperview().offset(17.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        tip.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(93.autoWidth())
            make.left.equalToSuperview().offset(17.autoWidth())
            make.height.equalTo(15.autoWidth())
            make.bottom.equalToSuperview().offset(-23.autoWidth())
        }
        
        gong.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(19.autoWidth())
            make.right.equalTo(zhifuPrice.snp.left).offset(-5.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        zhifuPrice.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(18.autoWidth())
            make.right.equalToSuperview().offset(-15.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        fangfeiPrict.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(66.autoWidth())
            make.right.equalToSuperview().offset(-15.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        zaocanPrice.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(93.autoWidth())
            make.right.equalToSuperview().offset(-15.autoWidth())
            make.height.equalTo(15.autoWidth())
        }
        lineView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(48.autoWidth())
            make.left.equalToSuperview().offset(15.autoWidth())
            make.right.equalToSuperview().offset(-15.autoWidth())
            make.height.equalTo(0.5.autoWidth())
        }
        
        
    }
}
